//
//  HomeModeViewCell.swift
//  WatermarkCamera
//
//  Created by 赵新 on 5/7/2024.
//

import UIKit
import AxcBedrock

// MARK: - [HomeModeViewCell.Model]

extension HomeModeViewCell {
    class Model {
        init(title: String,
             width: CGFloat = 35,
             isUseSelect: Bool = true,
             didSelectBlock: AxcBlock.OneParam<Model>? = nil) {
            self.title = title
            self.width = width
            self.isUseSelect = isUseSelect
            self.didSelectBlock = didSelectBlock
        }

        var title: String = ""
        var width: CGFloat = 35
        var isSelect: Bool = false // 选中状态
        var isUseSelect: Bool = true // 是否可以被选中，如果不能被选中，则只会回调Block
        var didSelectBlock: AxcBlock.OneParam<Model>?
    }
}

// MARK: - [HomeModeViewCell]

class HomeModeViewCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        createUI()
    }

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    lazy var headlineLabel: UILabel = {
        let label = UILabel()
        label.adjustsFontSizeToFitWidth = true
        return label
    }()

    lazy var pointView: UIView = {
        let view = UIView()
        view.backgroundColor = "323233".axc.uiColor
        view.layer.cornerRadius = 2
        view.layer.masksToBounds = true
        view.isHidden = true
        return view
    }()

    var isTransparent: Bool = false

    func createUI() {
        headlineLabel.textAlignment = .center
        headlineLabel.textColor = "323233".axc.uiColor
        addSubview(headlineLabel)
        addSubview(pointView)
        
        headlineLabel.snp.makeConstraints { make in
            make.top.equalTo(4)
            make.left.right.equalToSuperview()
        }

        pointView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(headlineLabel.snp.bottom).offset(4)
            make.size.equalTo(4)
        }
    }

    func configModel(_ model: Model) {
        headlineLabel.text = model.title

        pointView.isHidden = !model.isSelect
        if isTransparent { // 透明
            pointView.backgroundColor = .white
        } else {
            pointView.backgroundColor = "0177FF".axc.uiColor
        }
        if model.isSelect {
            if isTransparent { // 透明
                headlineLabel.textColor = .white
            } else {
                headlineLabel.textColor = "0177FF".axc.uiColor
            }
            headlineLabel.font = 15.axc.uiFont(weight: .medium)
        } else {
            if isTransparent { // 透明
                headlineLabel.textColor = .white
            } else {
                headlineLabel.textColor = "8A8A99".axc.uiColor
            }
            headlineLabel.font = 15.axc.uiFont(weight: .regular)
        }
    }
}
